/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the license found in the LICENSE file in
 * the root directory of this source tree.
 *
 * @noflow
 * @format
 */
'use strict';

/* eslint nuclide-internal/no-commonjs: 0 */
/* eslint-disable no-console */

const SignedSource = require('signedsource');

function getFBFormatGeneratedModule(buildCommand) {
  return ({
    documentType,
    docText,
    concreteText,
    flowText,
    hash,
    devTextGenerator,
  }) => {
    const objectName =
      documentType === 'ConcreteOperation' ? 'batch' : 'fragment';
    const docTextComment = docText ? '\n/*\n' + docText.trim() + '\n*/\n' : '';
    const hashText = hash ? `\n * ${hash}` : '';
    const devOnlyText = devTextGenerator ? devTextGenerator(objectName) : '';
    const source =
      `
/**
 * Copyright 2004-present Facebook. All Rights Reserved.
 *
 * This file was generated by:
 *   ${buildCommand}
 *
 * ${SignedSource.getSigningToken()}${hashText}
 * ${'@'}flow
 * ${'@'}nogrep
 */

/* eslint-disable */

'use strict';

/*::
// flowlint untyped-type-import:off
import type { ${documentType} } from 'relay-runtime';
${flowText || ''}
*/

${docTextComment}
const ${objectName} /*: ${documentType}*/ = ${concreteText};
${devOnlyText}
module.exports = ${objectName};
`.trim() + '\n';
    return SignedSource.signFile(source);
  };
}

module.exports = getFBFormatGeneratedModule;
